package free6om.research.qart4j;

/**
 * @Copyright © 2017 sanbo Inc. All rights reserved.
 * @Description: 应该是和生成图片的XQR操作。Mask只和数据区进行XOR，不影响功能区
 * @Version: 1.0
 * @Create: 7/20/15
 * @Author: free6om
 */
public class Mask {
    private int mask;

    public Mask(int mask) {
        this.mask = mask;
    }

    public int getMask() {
        return mask;
    }

    public void setMask(int mask) {
        this.mask = mask;
    }

    /**
     * 掩码图地址:https://coolshell.cn/wp-content/uploads/2013/10/masking-pattern.png
     * 掩码图案的文献: doc/基于Reed-Solomon算法的QR码纠错编码.pdf
     * 
     * @param y
     * @param x
     * @return
     */
    public boolean shouldInvert(int y, int x) {
        switch (mask) {
        case 0:
            return (y + x) % 2 == 0;
        case 1:
            return y % 2 == 0;
        case 2:
            return x % 3 == 0;
        case 3:
            return (y + x) % 3 == 0;
        case 4:
            return (y / 2 + x / 3) % 2 == 0;
        case 5:
            return y * x % 2 + y * x % 3 == 0;
        case 6:
            return (y * x % 2 + y * x % 3) % 2 == 0;
        case 7:
            return (y * x % 3 + (y + x) % 2) % 2 == 0;
        }

        return false;
    }
}
